package net.ght.bishe.bishe.controller;

import net.ght.bishe.bishe.entity.AjaxResponse;
import net.ght.bishe.bishe.entity.User;
import net.ght.bishe.bishe.entity.User_Status;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {




    @RequestMapping("/hello")
    public String toLogin() {
        return "login";
    }

    @ResponseBody
    @RequestMapping("/login")
    public AjaxResponse login(User user){
        System.out.println(user.toString());
        AjaxResponse ajaxResponse=new AjaxResponse();
        if(user.getUsername().equals("admin")){
            user.setUser_status(User_Status.ADMIN);
            ajaxResponse.setData(user);
            ajaxResponse.setMessage("it‘s admin");
        }else if(user.getPassword().equals("123")){
            user.setUser_status(User_Status.NORMAL);
            ajaxResponse.setData(user);
            ajaxResponse.setMessage("it‘s a user");
        }
        user.setUser_status(User_Status.NOT_LOGIN);
        ajaxResponse.setData(user);
        return ajaxResponse;
    }


//    @ResponseBody
//    @RequestMapping("/login")
//    public String login(User user) {
//        System.out.println(user.toString());
//        if(user.getPassword().equals("123")){
//            return "index";
//        }
//        return "login";
//    }


//    @RequestMapping("/login")
//    public String login(){
//        return "index";
//    }

    @RequestMapping("/test")
    public String toIndex(User user) {
        System.out.println(user.toString());
        return "index";
    }


}
